import { useEffect, useState } from "react";

//导入请求
import { Staff_Leave,Staff_Job,companyBuild_list,LimitPlan_list } from '../../tools/api'

//自定义钩子函数(员工状态)
export function useStaffLeaveList() {

    //定义组件状态
    const [staffLeaveList, setStaffLeaveList] = useState([])
    //发请求获取数据
    useEffect(() => {
        Staff_Leave().then((res) => {
            var arr = res.data.map((item) => {
                return { label: item.Leavename, value: item.Leavename }
            })
            setStaffLeaveList(arr)
        })
    }, [])
    return [staffLeaveList, setStaffLeaveList]
}

//自定义钩子函数(员工职位)
export function useStaffManageJob() {

    //定义组件状
    const [staffManageJob, setStaffManageJob] = useState([])
    //发请求获取数据
    useEffect(() => {
        Staff_Job().then((res) => {
            var arr = res.data.map((item) => {
                return { label: item.Jobname, value: item.Jobname }
            })
            setStaffManageJob(arr)  
        })
    }, [])
    return [staffManageJob, setStaffManageJob]
}

//自定义钩子函数(公司架构列表)
export function useCompanyBuildTable() {

    //定义组件状态
    const [companyBuildTableList, setCompanyBuildTableList] = useState([])
    //发请求获取数据
    useEffect(() => {
        companyBuild_list().then((res) => {
            setCompanyBuildTableList(res.data)
        })
    }, [])
    return [companyBuildTableList, setCompanyBuildTableList]
}
//自定义钩子函数(权限分配数据列表)
export function useLimitPlanTable() {

    //定义组件状态
    const [limitPlanTableList, setLimitPlanTableList] = useState([])
    //发请求获取数据
    useEffect(() => {
        LimitPlan_list().then((res) => {
            // var arr = res.data.map((item,index) => {
            //     return { label: item.name, value: item.id }
            // })
            setLimitPlanTableList(res.data)
        })
    }, [])
    return [limitPlanTableList, setLimitPlanTableList]
}

